define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Linkemail, GoPage,GoDialog) {
		$scope.detail = new Object();
		
		//初始化页面
		$scope.init_data = function(){
			Linkemail.email_detail(function(data){
				if(data!=null)
				$scope.detail = data;
				else
				$scope.detail = new Object();
			})
		}
		$scope.init_data();
		
		//提交
		$scope.send_email = function(){
			if(!$scope.detail.password){
				GoDialog.toast("请填写密码");
				return;
			}else if($scope.detail.email==undefined){//type="email"较特殊，必须用undefined
				GoDialog.toast("请填写邮箱");
				return;
			}
			Linkemail.send_email($scope.detail.password,$scope.detail.email,function(data){
				if(data.success){
					GoDialog.toast(data.msg);
					GoPage.go_states("t-set");
				}else{
					GoDialog.alert("提示",data.msg);
				}
			})
		}
		
		//清空输入
		$scope.clearInput = function(type){
			if(type==1){
				$scope.detail.password = "";
			}else{
				$scope.detail.email = "";
			}
		}
		
		
	}

	controller.$inject = ['$scope', 'Linkemail', 'GoPage','GoDialog'];

	return app.registerController("linkemailctrl",controller);
});